package ThreadJoinTest;

/**
 * ClassName AThread
 * Description TODO
 * Author Hexiao
 * Date 2018/8/24 15:08
 * Version 1.0
 **/
public class AThread extends Thread {
    BThread bt;
    public AThread(BThread bt) {
        System.out.println("AThread constructor.....");
        this.bt = bt;
    }
    public void run() {
        String threadName = Thread.currentThread().getName();
        System.out.println(threadName + " start.");
        try {
            bt.join();//等到bt结束了才向下执行。
            for (int i = 0; i < 5; i++) {
                System.out.println(threadName + " loop at " + i);
                Thread.sleep(1000);
            }
            System.out.println(threadName + " end.");
        } catch (Exception e) {
            System.out.println("Exception from " + threadName + ".run");
        }
    }

}